/*
 *Copyright © 2015 HanHai
 *湖北汉海拍卖集团
 *All rights reserved.
 */
package temp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.hanhai.common.annotation.PermissionNeed;
import com.hanhai.common.web.controller.BaseController;
import com.hanhai.zrb.backend.util.BackendLoginUtil;

@Controller
@RequestMapping("getProEmail")
public class GetProjectInfoEmailcontroller extends BaseController {

	@Resource
	private GetProjectInfoEmailService getProjectInfoEmailService;

	@PermissionNeed("getproemail")
	@RequestMapping("index")
	public String index() {
		return "getproemail/list";
	}
	
	@RequestMapping("list")
	public void index(ProjectEmailDto projectEmailDto,HttpServletRequest request, HttpServletResponse response) throws IOException {
		if( StringUtils.isNotBlank(projectEmailDto.getBeginTimes())){
			projectEmailDto.setBeginTimes(projectEmailDto.getBeginTimes()+" 00:00:00") ;
		}else{
			projectEmailDto.setBeginTimes(null);
		}
		if( StringUtils.isNotBlank(projectEmailDto.getEndTimes())){
			projectEmailDto.setEndTimes(projectEmailDto.getEndTimes()+" 23:59:59") ;
		}else{
			projectEmailDto.setEndTimes(null);
		}
		if( StringUtils.isNotBlank(projectEmailDto.getSearchName())){
			projectEmailDto.setSearchName(projectEmailDto.getSearchName().trim());
		}else{
			projectEmailDto.setSearchName(null);
		}
		
		List<ProjectEmailDto> list = getProjectInfoEmailService.queryAll(projectEmailDto);
		int total = list.size();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", list);
		map.put("total", total);
		String str = JSONObject.toJSONString(map);
		response.getWriter().write(str);
	}

	@RequestMapping(value = "updateStatus")
	public void deleteUsers(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String ids = request.getParameter("ids");
		List<Integer> list = new ArrayList();
		String[] strs = ids.split(",");
		for (int i = 0; i < strs.length; i++) {
			list.add(Integer.parseInt(strs[i]));
		}
		long longId = BackendLoginUtil.getCurrentUser().getId();  
		int intId = (int)longId;
		getProjectInfoEmailService.updateStatusById(new Date(), intId, BackendLoginUtil.getCurrentUser().getUserName(), list);;
		List<ProjectEmailDto> listDto = getProjectInfoEmailService.queryAll(new ProjectEmailDto());
		int total = listDto.size();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", listDto);
		map.put("total", total);
		String str = JSONObject.toJSONString(map);
		response.getWriter().write(str);
	}
	
}
